var request = require('superagent'),
	should = require('should'),
	mocha = require('mocha');

describe('{{description}}', function() {
	var agent = request.agent();

	it('should {{description}}', function(done) {
		var path = require('path');
		var body = require(path.resolve('{{contentPath}}', '{{#request}}{{body}}{{/request}}'));
		agent
			.post('{{baseUrl}}{{url}}')
			{{#loginCredentials}}.auth('{{user}}', '{{pass}}'){{/loginCredentials}}
			.send(body)
			.set('Accept', 'application/json')
			.end(function(err, res) {
				should.not.exist(err);
				res.should.have.status({{response.statusCode}});
				res.should.have.property('body');
				// FIXME add further checks if appropriate
				{{#response.validationSchema}}
				var JaySchema = require('jayschema');
				var js = new JaySchema(JaySchema.loaders.http);
				var schema = require(path.resolve('{{contentPath}}', '{{response.validationSchema}}'));
				js.validate(res.body, schema, function(errs) {
					should.not.exist(errs);
					done();
				});
				{{/response.validationSchema}}
				{{^response.validationSchema}}done();{{/response.validationSchema}}
			});
	});
});